//
//  WHTreeManager.h
//  WHValueKit
//
//  Created by peng wang on 2023/2/21.
//

#import <Foundation/Foundation.h>

@class WHTreeItem;

@interface WHTreeManager : NSObject

// itemid和节点模型的关系映射
@property (nonatomic, strong, readonly) NSMutableDictionary<NSString *, WHTreeItem *> *itemsMap;

// 最顶级节点
@property (nonatomic, strong, readonly) NSMutableArray<WHTreeItem *> *topItems;

// 所有的节点
@property (nonatomic, strong, readonly) NSMutableArray<WHTreeItem *> *allItems;

// 可见的节点
@property (nonatomic, strong, readonly) NSMutableArray<WHTreeItem *> *showItems;

// 所有已经勾选的节点
@property (nonatomic, strong, readonly) NSArray<WHTreeItem *> *allCheckItem;

// 初始化，ExpandLevel 为 0 全部折叠，为 1 展开一级，以此类推，为 NSIntegerMax 全部展开
- (instancetype)initWithItems:(NSSet<WHTreeItem *> *)items andExpandLevel:(NSInteger)level;

// 获取指定的节点
- (WHTreeItem *)getItemById:(NSString *)itemId;
			
//// 通过当前节点获取最上层节点
//- (WHTreeItem *)getTopItemByCurrentItem:(WHTreeItem *)item;
//
//// 通过当前节点获取最底层第一级节点
//- (WHTreeItem *)getFirstLevelItemByCurrentItem:(WHTreeItem *)item;

// 获取当前节点下面所有子节点
- (NSArray *)getAllChildItemsWithItem:(WHTreeItem *)item;

// 获取当前节点上面所有父节点
- (NSArray *)getAllParentItemsWithItem:(WHTreeItem *)item;

// 判断两个节点是否为兄弟节点
- (BOOL)checkBrotherItemsBetweenItem1:(WHTreeItem *)item1 andItem2:(WHTreeItem *)item2;

// 展开/折叠到多少层级
- (void)expandItemWithLevel:(NSInteger)expandLevel
				  completed:(void(^)(NSArray *noExpandArray))noExpandCompleted
			   andCompleted:(void(^)(NSArray *expandArray))expandCompleted;

// 展开节点，返回所改变的节点的个数
- (NSInteger)expandItem:(WHTreeItem *)item;

// 展开节点，并展开下面所有第一层子节点
- (NSInteger)expandItem:(WHTreeItem *)item andExpandFirstLevelChildItemByDeep:(BOOL)isDeep completed:(void(^)(WHTreeItem *lastItem, NSInteger itemIndex))block;

// 展开任意指定节点，规则是按照该节点的所有父节点路径全部依次展开至该节点
- (NSInteger)expandAnyItem:(WHTreeItem *)item;

// 折叠节点，是否折叠该节点下的所有子节点
- (NSInteger)foldItem:(WHTreeItem *)item andFoldAllChildItems:(BOOL)isFoldChildItems;

// 删除叶子节点
- (void)deleteLeafItem:(WHTreeItem *)item;

// 勾选/取消勾选节点
- (void)checkItem:(WHTreeItem *)item isChildItemCheck:(BOOL)isChildItemCheck;
- (void)checkItem:(WHTreeItem *)item isCheck:(BOOL)isCheck isChildItemCheck:(BOOL)isChildItemCheck;

// 全部勾选/全部取消勾选
- (void)checkAllItem:(BOOL)isCheck;

// 筛选
- (void)filterField:(NSString *)field isChildItemCheck:(BOOL)isChildItemCheck;

@end
